package com.xj.ideatest.components;

import com.intellij.notification.Notification;
import com.intellij.notification.Notifications;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.ui.MessageType;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.xj.ideatest.utils.NotificationManager;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Data
@State(name = "com.xj.ideatest.components.Config", storages = @Storage("cs.xml"))
public class Config implements PersistentStateComponent<Config> {

    private String url;

    @Nullable
    @Override
    public Config getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull Config state) {
        XmlSerializerUtil.copyBean(state, this);
    }

    @Override
    public void initializeComponent() {
        System.out.println("持久化初始化");
        Notification notification = NotificationManager.getGroup().createNotification("持久化已经初始化成功", MessageType.INFO);
        Notifications.Bus.notify(notification);
    }
}
